//
//  XDTabBarController.m
//  ocweibo
//
//  Created by lucy on 2016/10/24.
//  Copyright © 2016年 com.huashengHuaSheng. All rights reserved.
//

#import "XDTabBarController.h"
#import "XDNavViewController.h"
#import "XDTabBarView.h"

@interface XDTabBarController ()

@end

@implementation XDTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    void(^myBlock)()=^{
    
        NSLog(@"中间的按钮被点击了");
    
    };
    
    //自定义TabBarView
    XDTabBarView* tabView = [[XDTabBarView alloc]init];
    tabView.btnBlock = myBlock;
    [self setValue:tabView forKey:@"tabBar"];
    
    [self setupTabView];
    
}


#pragma mark-加载底部标签栏
- (void)setupTabView{

    UIViewController* tab1 = [self loadTabBarVcWithName:@"XDHomeViewController"andTitleName:@"首页" andImageName:@"tabbar_home"];
    
    UIViewController* tab2 = [self loadTabBarVcWithName:@"XDMessageViewController"andTitleName:@"消息" andImageName:@"tabbar_message_center"];
    
    UIViewController* tab3 = [self loadTabBarVcWithName:@"XDDiscoverViewController"andTitleName:@"发现" andImageName:@"tabbar_discover"];
    
    UIViewController* tab4 = [self loadTabBarVcWithName:@"XDProfileViewController"andTitleName:@"我的" andImageName:@"tabbar_profile"];
    
    self.viewControllers = @[tab1,tab2,tab3,tab4];


}


#pragma mark-加载方法
- (UIViewController*)loadTabBarVcWithName:(NSString*)VcName andTitleName:(NSString*)titleName andImageName:(NSString*)imagName{
    
    Class clc = NSClassFromString(VcName);
    UIViewController* vc = [[clc alloc]init];
    vc.title = titleName;
    
    //设置tabBar图片的背景图片
    vc.tabBarItem.image = [[UIImage imageNamed:imagName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSString* selectImageName = [imagName stringByAppendingString:@"_selected"];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSDictionary* dict = @{NSForegroundColorAttributeName: [UIColor orangeColor]};
    [vc.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    
    XDNavViewController* nav = [[XDNavViewController alloc]initWithRootViewController:vc];
    return nav;
}

@end
























